package com.lyc.business.infrastructure.command.resignationGuidelines;

import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyc.business.infrastructure.mapper.resignationGuidelines.ResignationGuidelinesMapper;
import com.lyc.business.infrastructure.po.ResignationGuidelinesPo;
import com.lyc.common.command.BaseCommand;
import com.lyc.common.entity.ResignationGuidelinesReq;
import com.lyc.common.entity.ResignationGuidelinesVo;

/**
 * @Author 李大神仙
 * @Date 2024/2/23 18:53
 * @Version 1.0
 */

@Component
//public class ResignationGuidelinesCommand extends ServiceImpl<ResignationGuidelinesMapper, ResignationGuidelinesPo> {
public class ResignationGuidelinesCommand extends BaseCommand<ResignationGuidelinesMapper, ResignationGuidelinesPo> {

    @Autowired
    private ResignationGuidelinesMapper resignationGuidelinesMapper;

    public IPage<ResignationGuidelinesVo> selectResignationGuidelinesByPage(ResignationGuidelinesReq req){
        Page<ResignationGuidelinesReq> page = new Page<>(req.getPageNum(),req.getPageSize());
        IPage<ResignationGuidelinesVo> resignationGuidelinesVoIPage = resignationGuidelinesMapper.selectResignationGuidelinesByPage(
                page, req);
       // List<ResignationGuidelinesVo> records = resignationGuidelinesVoIPage.getRecords();
        //单张表查询可以使用mybatisplus自带的分页方法selectPage
      /*  LambdaQueryWrapper<ResignationGuidelinesPo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(ResignationGuidelinesPo::getId);
        Page<ResignationGuidelinesPo> pages = new Page<>(1,10);
        Page<ResignationGuidelinesPo> resignationGuidelinesPoPage = resignationGuidelinesMapper.selectPage(pages,
                queryWrapper);
        resignationGuidelinesPoPage.setTotal(10);*/

        return resignationGuidelinesVoIPage;
    }

    public void saveOrUpdateResignationGuidelines(ResignationGuidelinesReq req){
        ResignationGuidelinesPo resignationGuidelinesPo = new ResignationGuidelinesPo();
        resignationGuidelinesPo.setGuidelinesAme(req.getGuidelinesAme());
        resignationGuidelinesPo.setResignationTypeCode(req.getResignationTypeCode());
        resignationGuidelinesPo.setBelongingParkCode(req.getBelongingParkCode());
        resignationGuidelinesPo.setDivisionCode(req.getDivisionCode());
        resignationGuidelinesPo.setAddTime(LocalDateTime.now());
        this.saveOrUpdate(resignationGuidelinesPo);
    }
}
